package valueObjects
{
	import flash.utils.*;
	
	import mx.collections.ArrayCollection;
	import mx.collections.IViewCursor;
	import mx.collections.Sort;
	import mx.collections.SortField;
	
	public class Bill
	{
		[Bindable]
		public var provider:String;
		[Bindable]
		public var billTimeIn:Date();
		[Bindable]
		public var allItems:ArrayCollection = new ArrayCollection();    //单中的所有对象
		[Bindable]
		public var total:Number = 0;
		private var cursor:IViewCursor;
		public function Bill(_provider:String,_billTimeIn:Date)
		{
			this.provider = _provider;
			this.billTimeIn = _billTimeIn;
		}
		
		public function addItem(item:ShoppingCartItem):void {
			allItems.addItem(item);
			calcTotal();
		}
		
		private function calcTotal():void {
			this.total = 0;
			for(var i:int=0; i<allItems.length; i++){
				this.total += allItems.getItemAt(i).subtotal;
			}
		}
		private function sortItems():void {
			var prodSort:Sort = new Sort();
			var sortField:SortField = new SortField("product");
			prodSort.fields = new Array(sortField);
			allItems.sort = prodSort;
			allItems.refresh();
		}
		

	}
}